import os
import numpy as np

from src.config import config


class OtuData():
    def __init__(self, inputs, outputs=[], result_sample_id=[]):
        self._inputs = inputs
        self._outputs = outputs
        self._result_sample_id = result_sample_id
        self._indicator = 0

    def next_batch(self, batch_size):
        end_indicator = self._indicator + batch_size
        if end_indicator > len(self._inputs):
            self._indicator = 0
            end_indicator = batch_size
        if end_indicator > len(self._inputs):
            raise Exception("batch_size: %d is too large" % batch_size)

        batch_inputs = self._inputs[self._indicator: end_indicator]
        if len(self._outputs) > 0:
            batch_outputs = self._outputs[self._indicator: end_indicator]
        else:
            batch_outputs = None
        if len(self._result_sample_id) > 0:
            batch_sample_id = self._result_sample_id[self._indicator: end_indicator]
        else:
            batch_sample_id = None
        self._indicator = end_indicator
        return batch_inputs, batch_outputs, batch_sample_id


def get_logs_dir():
    logs_dir = config.logs_dir
    train_log_dir = os.path.join(logs_dir, "train")
    test_log_dir = os.path.join(logs_dir, "test")
    val_log_dir = os.path.join(logs_dir, "val")
    if not os.path.exists(logs_dir):
        os.mkdir(logs_dir)
    if not os.path.exists(train_log_dir):
        os.mkdir(train_log_dir)
    if not os.path.exists(test_log_dir):
        os.mkdir(test_log_dir)
    if not os.path.exists(val_log_dir):
        os.mkdir(val_log_dir)
    return train_log_dir, test_log_dir, val_log_dir
